package pub.guoxin.oops.model;


import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import pub.guoxin.oops.tidy.LocalDateTimeDeserializer;
import pub.guoxin.oops.tidy.LocalDateTimeSerializer;

import java.time.LocalDateTime;

/**
 * 万事万物皆对象
 * Created by guoxin on 17-10-17.
 */
@Data
@Entity
@ApiModel
public abstract class BaseEntity0<T> {

    @Id
    @ApiModelProperty(hidden = true)
    protected T id;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @ApiModelProperty(hidden = true)
    protected LocalDateTime creation;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @ApiModelProperty(hidden = true)
    protected LocalDateTime renewal;

    public void init() {
        this.creation = LocalDateTime.now();
        this.renewal = LocalDateTime.now();
    }

}
